package org.example.nuaael;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author : zhangbo
 * @data : 2024/6/21
 * @description :
 */
public class test3 {
    public static void main(String[] args) {
        // 示例时间，实际使用时可以替换为动态获取的时间
        String inputTime = "2024-06-21 14:45:30";

        LocalDateTime dateTime = LocalDateTime.parse(inputTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        // 截取出时和分
        LocalTime time1 = dateTime.toLocalTime();
        int hour = time1.getHour();
        int minute = time1.getMinute();
        inputTime=hour+":"+minute;
        LocalTime time = LocalTime.parse(inputTime, DateTimeFormatter.ofPattern("HH:mm"));
        String period = getPeriodForTime(time);
        System.out.println("The time " + inputTime + " falls in the period: " + period);


    }

    public static String getPeriodForTime(LocalTime time) {
        if (time.isBefore(LocalTime.of(11, 0)) || time.isAfter(LocalTime.of(17, 0))) {
            // 早上 6:00 - 11:00 或 晚上 19:00 - 6:00
            return time.isBefore(LocalTime.of(6, 0)) ? "晚上" : "早上";
        } else if (time.isAfter(LocalTime.of(11, 0)) && time.isBefore(LocalTime.of(17, 0))) {
            // 中午 11:00 - 17:00
            return "中午";
        } else {
            // 傍晚 17:00 - 19:00
            return "傍晚";
        }
    }
}
